<template>
	<view class="mine-container" :style="{height: `${windowHeight}px`}">
		<!--顶部个人信息栏-->
		<view class="header-section">
			<view class="flex justify-between" style="align-items: center;">
				<view class="flex align-center">

					<view v-if="!avatar" class="cu-avatar xl round bg-white">
						<view class="iconfont icon-people text-gray icon"></view>
					</view>
					<view class="user-avatar">
						<view class=" cu-avatar xl round bg-white " v-if="avatar" @click="handleToAvatar">
							<image :src="avatar" class="cu-avatar round bg-white "></image>
							<!-- <u--image class="" mode="widthFix" :src="avatar" width="100%">
								<view slot="error" style="font-size: 24rpx;">
									<image src="@/static/morentx.jpg" class="cu-avatar xl round" mode="widthFix">
								</view>
							</u--image> -->
						</view>
						<image v-else @click="handleToAvatar" src="@/static/morentx.jpg" class="cu-avatar xl round"
							mode="widthFix">
						</image>
						<!-- <image @click="handleToAvatar" :src="avatar" class="cu-avatar xl round"
							mode="widthFix">
						</image>
						<image v-else @click="handleToAvatar" src="@/static/morentx.jpg" class="cu-avatar xl round"
							mode="widthFix">
						</image> -->
						<view class="avatar-tag white">vip</view>
					</view>
					<view v-if="!name" @click="handleToLogin" class="login-tip">
						点击登录
					</view>
					<view v-if="name" class="user-info">
						<view class="u_title">
							{{ name }}
						</view>
						<view class="" v-if="phoneNumber">
							{{phoneNumber}}
						</view>
						<view class="" style="font-size: 26rpx;" @click.stop="copyCode" v-if="invitationCode">
							邀请码：
							<text>{{invitationCode}}</text>
						</view>
					</view>
				</view>
				<view class="flex align-center sign" @click="toSign">
					<text>{{signIn?'已签到':'签到'}} </text>
				</view>
				<!-- 		<view @click="handleToInfo" class="flex align-center">
					<text>个人信息</text>
					<view class="iconfont icon-right"></view>
				</view> -->
			</view>
		</view>
		<view class="main">
			<view class="user-vip" style="padding-bottom: 130rpx;">
				<view class="user-assets-box">
					<view class="user-assets-header row-between">
						<!-- @click="goPage('/pages/bundle/user_bill/user_bill?type=0')" -->
						<view class="row nr bold" style="line-height: 80rpx;color: #8F430E;">
							可提现积分：
							<priceFormat weight="bold" :showSubscript="true" :firstSize="36" :subscriptSize="26"
								:secondSize="36" :price="able_withdrawal" color="#FF2C3C" />
						</view>
						<navigator hover-class="none" class="primary-btn white row-center"
							url="/pages/mine/withdrawal/withdrawal">立即提现</navigator>
					</view>
					<view class="user-assets-content row wrap">
						<view class="user-item column-center">
							<view class="nr user-assets-name row" style="color: #8F430E">
								我的推荐
							</view>
							<view class="assets ">
								<priceFormat weight="bold" :showSubscript="true" :firstSize="36" :subscriptSize="26"
									:secondSize="36" :price="totalRem" color="#FF2C3C" />
							</view>
						</view>
						<view class="user-item column-center" @click="toTeam">
							<view class="nr user-assets-name row" style="color: #8F430E">
								我的团队
								<!-- <u-icon class="ml10" name="question-circle" size="30rpx" color="#D88D5A" /> -->
							</view>
							<view class="assets ">
								<priceFormat weight="bold" :showSubscript="true" :firstSize="36" :subscriptSize="26"
									:secondSize="36" :price="teamUser" color="#FF2C3C" />
							</view>
						</view>
						<view class="user-item column-center">
							<view class="nr user-assets-name row" style="color: #8F430E">
								团队新增<!-- <u-icon class="ml10" name="question-circle" size="30rpx" color="#D88D5A" /> -->
							</view>
							<view class="assets">
								<priceFormat weight="bold" :showSubscript="true" :firstSize="36" :subscriptSize="26"
									:secondSize="36" :price="totalTeamAdd" color="#FF2C3C" />
							</view>
						</view>
					</view>

				</view>
				<view class="usual-tools-box bg-white mt20">
					<view class="usual-tools-header row lg bold">
						常用工具
					</view>
					<view class="menu-list">
						<view class="list-cell list-cell-arrow">
							<navigator class="menu-item-box" navigator hover-class="none"
								url="/pages/mine/integral/integral">
								<uni-icons type="star" color="#ff3140"></uni-icons>
								<view style="margin-left: 10rpx;">我的积分</view>
							</navigator>
						</view>
						<navigator hover-class="none" url="/pages/mine/sign/sign" class="list-cell list-cell-arrow"
							@click="handleToPhone">
							<view class="menu-item-box">
								<uni-icons type="shop" color="#ff3140"></uni-icons>
								<view style="margin-left: 10rpx;">签到记录</view>
							</view>
						</navigator>
						<navigator hover-class="none" url="/pages/mine/prize/prize" class="list-cell list-cell-arrow"
							@click="handleToUpgrade">
							<view class="menu-item-box">
								<uni-icons type="shop" color="#ff3140"></uni-icons>
								<view style="margin-left: 10rpx;">我的奖品</view>
							</view>
						</navigator>
						<navigator hover-class="none" url="/pages/mine/order/order" class="list-cell list-cell-arrow">
							<view class="menu-item-box">
								<uni-icons type="list" color="#ff3140"></uni-icons>
								<view style="margin-left: 10rpx;">商城订单</view>
							</view>
						</navigator>
						<navigator hover-class="none" url="/pages/mine/comboOrder/comboOrder"
							class="list-cell list-cell-arrow">
							<view class="menu-item-box">
								<uni-icons type="list" color="#ff3140"></uni-icons>
								<view style="margin-left: 10rpx;">套餐订单</view>
							</view>
						</navigator>
						<navigator hover-class="none" class="list-cell list-cell-arrow" @click="handleAddress">
							<view class="menu-item-box">
								<uni-icons type="list" color="#ff3140"></uni-icons>
								<view style="margin-left: 10rpx;">我的收货地址</view>
							</view>
						</navigator>
						<view class="list-cell list-cell-arrow" @click="handleAbout">
							<view class="menu-item-box">
								<!-- <uni-icons type="gear" color="#ff3140"></uni-icons> -->
								<view class="iconfont icon-aixin menu-icon" style="color: #ff3140;"></view>
								<view>关于我们</view>
							</view>
						</view>
						<view class="list-cell list-cell-arrow" @click="handleToSetting">
							<view class="menu-item-box">
								<uni-icons type="gear" color="#ff3140"></uni-icons>
								<view style="margin-left: 10rpx;">应用设置</view>
							</view>
						</view>
					</view>
					<!-- 					<view class="usual-content row">
						<navigator hover-class="none" url="/pages/mine/integral/integral"
							class="usual-item column-center">
							<image src="@/static/images/jf.png" class="usual-item-img"></image>
							<view class="nr normal mt20" style="line-height: 40rpx">积分</view>
						</navigator>
						<navigator hover-class="none" url="/pages/mine/sign/sign" class="usual-item column-center">
							<image src="@/static/images/qd.png" class="usual-item-img"></image>
							<view class="nr normal mt20" style="line-height: 40rpx">签到记录</view>
						</navigator>
						<navigator hover-class="none" url="/pages/mine/prize/prize" class="usual-item column-center">
							<image src="@/static/images/jp.png" class="usual-item-img"></image>
							<view class="nr normal mt20" style="line-height: 40rpx">奖品</view>
						</navigator>
						<navigator hover-class="none" url="/pages/mine/order/order" class="usual-item column-center">
							<image src="@/static/images/order-mine.png" class="usual-item-img"></image>
							<view class="nr normal mt20" style="line-height: 40rpx">订单</view>
						</navigator>
						<view @click="handleToSetting" class="usual-item column-center">
							<image src="@/static/images/set.png" class="usual-item-img"></image>
							<view class="nr normal mt20" style="line-height: 40rpx">设置</view>
						</view>
					</view> -->
				</view>
			</view>
		</view>
		<view class="content-section">
			<!-- 			<view class="menu-list">
				<view class="list-cell list-cell-arrow" @click="handleToEditInfo">
					<view class="menu-item-box">
						<view class="iconfont icon-user menu-icon"></view>
						<view>编辑资料</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="handleHelp">
					<view class="menu-item-box">
						<view class="iconfont icon-help menu-icon"></view>
						<view>常见问题</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="handleAbout">
					<view class="menu-item-box">
						<view class="iconfont icon-aixin menu-icon"></view>
						<view>关于我们</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="handleToSetting">
					<view class="menu-item-box">
						<view class="iconfont icon-setting menu-icon"></view>
						<view>应用设置</view>
					</view>
				</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	import priceFormat from '@/components/price-format/price-format.vue';
	import {
		signInApi,
		getTotalPointsApi,
		getTeamUserNumApi,
		getPhoneApi,
		getMyRecommendApi,
		getTeamAddApi
	} from '@/api/index.js';
	import {
		getInfo
	} from '@/api/login';
	import config from '@/config';
	export default {
		data() {
			return {
				name: this.$store.state.user.name,
				able_withdrawal: 0,
				history_earnings: 0,
				today_earnings: 0,
				signIn: false, //今日是否已签到
				teamUser: 0, //团队人数
				phoneNumber: '',
				invitationCode: null,
				totalRem: 0, //我的推荐
				totalTeamAdd: 0, //团队新增
			}
		},
		components: {
			priceFormat
		},
		computed: {
			avatar() {
				return this.$store.state.user.avatar
			},
			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		onShow() {
			console.log('页面显示');
			this.getUserInfo();
			this.getTotalPoints();
			this.getTeamUserNum();
			this.getPhone();

			this.getTeamAdd(); //团队新增
		},
		methods: {
			async getPhone() {
				const res = await getPhoneApi(uni.getStorageSync('UserInfo').userId);
				console.log(res, 'res');
				if (res.code != 200) return
				this.phoneNumber = res.msg;
			},
			async getMyRecommend() {
				const res = await getMyRecommendApi(this.invitationCode);
				console.log(res, 'res');
				if (res.code != 200) return
				this.totalRem = res.data;
				console.log('我的推荐', res);
			},
			async getTeamAdd() {
				const res = await getTeamAddApi(uni.getStorageSync('UserInfo').userId);
				console.log(res, 'res');
				if (res.code != 200) return
				console.log('团队新增', res);
				this.totalTeamAdd = res.data;
			},


			// 查询团队下面的人数
			async getTeamUserNum() {
				const res = await getTeamUserNumApi(uni.getStorageSync('UserInfo').userId);
				console.log(res, '查询团队下面的人数');
				if (res.code === 200) {
					this.teamUser = res.data;
				}
			},
			// 查询用户总积分
			async getTotalPoints() {
				const res = await getTotalPointsApi(uni.getStorageSync('UserInfo').userId);
				console.log(res, '查询用户总积分');
				if (res.code === 200) {
					this.able_withdrawal = res.data.availablePoints;
				}
			},
			// 获取用户信息
			getUserInfo() {
				getInfo().then(res => {
					console.log(res.user, '获取用户信息');
					this.invitationCode = res.user.invitationCode;
					this.signIn = res.user.signIn || false;
					this.getMyRecommend(); //我的推荐
				})
			},

			// 签到
			async toSign() {
				if (this.signIn) {
					uni.showToast({
						title: '今日已签到',
						icon: 'none'
					})
					return
				}
				const res = await signInApi(uni.getStorageSync('UserInfo').userId);
				console.log(res, 'res-签到');
				if (res && res.code === 200) {
					uni.showToast({
						title: '签到成功'
					})
					this.getUserInfo();
				}
			},
			copyCode() {
				console.log('666');
				uni.setClipboardData({
					data: this.invitationCode,
				})
			},
			toTeam() {
				this.$tab.navigateTo('/pages/mine/team/team')
			},
			handleToInfo() {
				this.$tab.navigateTo('/pages/mine/info/index')
			},
			handleToEditInfo() {
				this.$tab.navigateTo('/pages/mine/info/edit')
			},
			handleToSetting() {
				this.$tab.navigateTo('/pages/mine/setting/index')
			},
			handleAddress() {
				this.$tab.navigateTo('/pages/mine/address/address')
			},
			handleToLogin() {
				this.$tab.reLaunch('/pages/login')
			},
			handleToAvatar() {
				this.$tab.navigateTo('/pages/mine/avatar/index')
			},
			handleHelp() {
				this.$tab.navigateTo('/pages/mine/help/index')
			},
			handleAbout() {
				this.$tab.navigateTo('/pages/mine/about/index')
			},
			handleJiaoLiuQun() {
				this.$modal.showToast('QQ群：①133713780(满)、②146013835(满)、③189091635')
			},
			handleBuilding() {
				this.$modal.showToast('模块建设中~')
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f5f6f7;
	}

	.mine-container {
		width: 100%;
		height: 100%;


		.header-section {
			padding: 15px 15px 45px 15px;
			// background-color: #3c96f3;
			background-image: url('@/static/images/mine-bg.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
			color: white;
			height: 145px;

			.login-tip {
				font-size: 18px;
				margin-left: 10px;
			}

			.cu-avatar {
				width: 57px !important;
				height: 57px !important;
				max-height: 57px !important;
				max-width: 57px !important;
				// border: 2px solid #eaeaea;

				.icon {
					font-size: 40px;
				}
			}

			.user-info {
				margin-left: 15px;

				.u_title {
					font-size: 18px;
					line-height: 30px;
					font-weight: 600;
				}
			}
		}

		.content-section {
			position: relative;
			top: -50px;

			.mine-actions {
				margin: 15px 15px;
				padding: 20px 0px;
				border-radius: 8px;
				background-color: white;

				.action-item {
					.icon {
						font-size: 28px;
					}

					.text {
						display: block;
						font-size: 13px;
						margin: 8px 0px;
					}
				}
			}
		}
	}

	.user-avatar {
		width: 110rpx;
		height: 110rpx;
		position: relative;

		.avatar-tag {
			position: absolute;
			bottom: -16rpx;
			left: 15rpx;
			width: 80rpx;
			background-color: #F79C0C;
			border: 1rpx solid #FFFFFF;
			border-radius: 100rpx;
			font-size: 26rpx;
			// line-height: 30rpx;
			text-align: center;
		}
	}

	.main {
		padding: 0 20rpx;
		margin-top: -60rpx;

		.user-vip {
			.user-assets-box {
				background-color: #fff;
				border-radius: 20rpx;
				padding: 10rpx 20rpx 22rpx;
				background: linear-gradient(90deg, #FBEFDB 0%, #FED09E 100%);

				.user-assets-header {
					border-bottom: 1rpx dashed #8F430E;
					padding-bottom: 4rpx;

					.primary-btn {
						text-align: center;
						height: 54rpx;
						line-height: 54rpx;
						border-radius: 120rpx;
						width: 144rpx;
						background: linear-gradient(180deg, #FF3067 0%, #FF2C3C 100%);
					}
				}

				.user-assets-content {
					margin-top: 30rpx;

					.user-item {
						flex: 1;
						position: relative;

						.user-assets-name {
							// border: 1rpx solid #000;
							width: 100%;
							text-align: center;
							align-self: flex-start;
							justify-content: center;
						}

						.assets {
							margin-top: 14rpx;
							text-align: center;
							align-self: flex-start;
							// border: 1rpx solid #000;
							width: 100%;
						}

						// &:last-of-type .assets {
						//     align-self: center;
						//     margin-top: 14rpx;
						//     text-align: left;
						// }
					}
				}
			}

			.fans-msg-box {
				border-radius: 10rpx;
				line-height: 42rpx;

				.my-fans {
					width: 50%;
					height: 120rpx;
				}

				.line {
					width: 3rpx;
					height: 60rpx;
					background-color: #E5E5E5;
				}

				.invite-fans {
					width: 50%;
					height: 120rpx;
				}
			}

			.my-invite-box {
				padding: 26rpx 0 57rpx;
				border-radius: 10rpx;

				.invite-copy-btn {
					line-height: 30rpx;
					padding: 10rpx;
					background: linear-gradient(90deg, #FEE4B4 0%, #FBCB96 100%);
					color: #8F430E;
					border-radius: 4rpx;
				}

				.my-promote-banner {
					margin-top: 30rpx;
					height: 148rpx;
					width: 542rpx;
					border-radius: 10rpx;
				}
			}

			.usual-tools-box {
				border-radius: 10rpx;
				padding: 25rpx;

				.usual-tools-header {
					color: #000;
					height: 70rpx;
					// line-height: 44rpx;
					border-bottom: 1px solid #E5E5E5;
				}

				.usual-content {
					width: 625rpx;
					padding: 40rpx 0;
					// border: 1rpx solid #000;

					.usual-item {
						width: 25%;
						// border: 1rpx solid #000;

						.usual-item-img {
							width: 64rpx;
							height: 64rpx;
							flex: none;
						}

					}
				}
			}
		}

		.user-apply-box {
			.user-apply-vip {
				background-color: white;
				padding: 40rpx 0 0rpx;
				border-radius: 20rpx;

				.title {
					line-height: 30rpx;
					font-weight: bold;
				}

				.explain {
					margin-top: 20rpx;

					image {
						width: 24rpx;
						height: 24rpx;
						flex: none;
					}

					span {
						font-size: 20rpx;
						line-height: 30rpx;
					}
				}

				.vip-form {
					width: 100%;
					flex: 1;
					margin-top: 60rpx;

					.form-item {
						padding: 24rpx 0 24rpx 30rpx;
						border: 1rpx solid #000;
						margin: 0 34rpx 30rpx;

						.label {
							width: 150rpx;
							line-height: 30rpx;
						}

						input {
							flex: 1;
							font-size: 30rpx;
							margin-left: 10rpx;
							line-height: 30rpx;
							padding-right: 20rpx;
						}
					}
				}
			}

			.apply-btn {
				line-height: 30rpx;
				height: 82rpx;
			}
		}

		.user-result-box {
			.user-result {
				background-color: white;
				padding: 36rpx 14rpx 50rpx;
				border-radius: 20rpx;

				.user-result-header {
					.title {
						line-height: 30rpx;
						font-weight: bold;
					}

				}

				.user-result-content {
					padding: 60rpx 0 22rpx;
					/* margin: 0 8px; */
					width: 100%;
					border-bottom: 1rpx solid #8F430E;

					.apply-result-img {
						width: 100rpx;
						height: 100rpx;
					}
				}

				.user-result-info {
					margin-top: 42rpx;
					width: 100%;

					.info-item {
						margin-left: 60rpx;
						margin-bottom: 28rpx;
						line-height: 30rpx;

						.label {
							width: 140rpx;
						}
					}
				}
			}

			.apply-btn {
				line-height: 30rpx;
				height: 82rpx;
			}

			.bg-gray {
				background-color: #CCCCCC;
			}
		}
	}

	.sign {
		text-align: center;
		height: 54rpx;
		line-height: 54rpx;
		border-radius: 120rpx;
		width: 144rpx;
		color: #ff2e50;
		background: #fff;

		text {
			width: 100%;
		}
	}
</style>